package com.zyp.messageboard.controller;
import com.zyp.messageboard.entity.Message;
import com.zyp.messageboard.service.MessageService;
import com.zyp.messageboard.service.impl.MessageServiceImpl;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/messageDetail")
public class MessageDetailServlet extends HttpServlet {

    private final MessageService messageService = new MessageServiceImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Integer messageId = Integer.parseInt(request.getParameter("id"));
        Message message = messageService.findById(messageId);
        request.setAttribute("message", message);
        request.getRequestDispatcher("messageDetail.jsp").forward(request, response);
    }
}
